<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="str" uri="/WEB-INF/config/tld/string-util.tld" %>
<jsp:include page="../include/header.jsp" />
<script type="text/javascript" src="<c:url value='/htmlRes/js/tableAddDelete.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/datepicker/jquery.ui.core.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/datepicker/jquery.ui.datepicker.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/jquery.form.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/fileUpload.js'/>"></script>
<script type="text/javaScript">
<!--
	/* pagination 페이지 링크 function */
	function listPage(){
		$('#writeForm').attr('action', '<c:url value="/daily/dailyList.do"/>');
		$('#writeForm').submit();
	}
	
	function saveFormPage() {
		$('#writeForm').attr('action', '<c:url value="/daily/dailySave.do"/>');
		$('#writeForm').submit();
	}
	
	function appendRow(id, sampleId){
		$('#'+id).appendRow({sampleTRObj:sampleId});
	}
	
	function deleteRow(id){
		$('#'+id).deleteRow();
	}
	function onchangeDate(id){
		$.ajax({
			type : "POST" ,
			url : "<c:url value='/daily/dailyDateChange.do'/>",
			dataType: 'json',
			data : 'dateId='+id,
			success: function(data) {
				$('#pre_sdl_iflow_dwater').val(data.iflowDwater);
				$('#pre_sdl_oflow_dwater').val(data.oflowDwater);
				$('#pre_sdl_elect_number').val(data.electNumber);
				calcAtype();
				cheangeInvenPre(data.inven);
			}, 
			error: function(request, status, err) {
				alert(request.status);
			}
		});
		$('#_dailyDate').html(id);
	}
	
	function cheangeInvenPre(obj){
		$('._codeKey').each(function(index){
			var _this = this;
			for(var i=0;i<obj.length;i++){
				if($(_this).val() == obj[i].invenKey){
					$('.preTs').eq(index).val(obj[i].invenPreTotalStock);
				}
			}
		});
		calcBtype();
	}
	
	function calcAtype(){
		$('._calcAtype').each(function(index){
			var _td = $(this).children("td");
			var preData = _td.eq(1).children("input").val();
			var nowData = _td.eq(2).children("input").val();
			if(nowData == ""){
				_td.eq(2).children("input").val("0");
				nowData = 0;
			}
			_td.eq(3).html(eval(nowData)-eval(preData));
		});
	}
	
	function calcBtype(){
		$('._calcBtype').each(function(index){
			var _td = $(this).children("td");
			var preStock = _td.eq(2).children("input").val();
			var nowUseData = _td.eq(4).children("input").val();
			var inputData = _td.eq(5).children("input").val();
			if(preStock == ""){
				_td.eq(2).children("input").val("0");
				preStock = 0;
			}
			if(nowUseData == ""){
				_td.eq(4).children("input").val("0");
				nowUseData = 0;
			}
			if(inputData == ""){
				_td.eq(5).children("input").val("0");
				inputData = 0;
			}
			var nowStock = eval(preStock)+eval(inputData)-eval(nowUseData);
			_td.eq(3).children("input").val(nowStock);
		});
	}
	function focusInput(obj){
		$(obj).val("");
	}
	function outfocusInput(obj){
		if($(obj).val() == "")
			$(obj).val("0");
	}
	
	var fileOtions;
	$(document).ready(function(){
		$('#_dailyDate').click(function(){
			$("#sdl_daily_date").css('width', '1px');
			$("#sdl_daily_date").focus();	
		});
		$("#sdl_daily_date").datepicker();
		
		calcAtype();
		calcBtype();
		$("._subCalcA").keyup(function(){
			calcAtype();
		});
		$("._subCalcA").focus(function(){
			$(this).val("");
		});
		$("._subCalcA").focusout(function(){
			if($(this).val() == "")
				$(this).val("0");
		});
		
		fileOtions = {fileObjId:"file",fileType:"attach",toObj:"sdl_dlog_file",showFileInfo:"fileInfo",oriNameUsed:true};
	});
	
	
	function fileDelete(){
		var dailyKey = $.trim($('#sdl_dlog_key').val());
		if(dailyKey==''){
			return;
		}
		$.ajax({
			type : "POST" ,
			url : "<c:url value='/daily/deleteAttachFile.do'/>",
			dataType: 'html',
			data : 'sdl_dlog_key='+dailyKey,
			success: function(data) {
				if(data == "true"){
					$('#sdl_dlog_file').val('');
					$('#fileInfo').html('');
				}else{
					alert("파일 삭제 실패!");
				};
			}, 
			error: function(request, status, err) {
				alert(request.status);
			}
		});
	}
	
-->
</script>

<!-- contents s -->
	<div class="container" id="container">
		<span class="round lt">&nbsp;</span>
		<span class="round rt">&nbsp;</span>
		<span class="round lb">&nbsp;</span>
		<span class="round rb">&nbsp;</span>
		<div class="container_area">
			<form name="writeForm" id="writeForm" action="<c:url value="/daily/dailyWriteForm.do"/>" method="post">
				<input type="hidden" name="sdl_dlog_file" id="sdl_dlog_file" value="${resultVO.sdl_dlog_file }"/>
				<input type="hidden" name="sdl_dlog_key" id="sdl_dlog_key" value="${resultVO.sdl_dlog_key }"/>
				<input type="hidden" name="sdl_area_key" id="sdl_area_key" value="${resultVO.sdl_area_key }"/>
			<h2 class="tit_h2"><input type="text" name="sdl_daily_date" id="sdl_daily_date" value="${resultVO.sdl_daily_date }" onchange="onchangeDate(this.value);" style="width:1px;border:0;"/><span id="_dailyDate">${resultVO.sdl_daily_date }</span> 오수처리시설 점검 일지</h2>
				<jsp:include page="../include/navi.jsp" />
				<h3 class="tit_h3">오수 발생량 (㎥/일)</h3>
				<div class="table_wrap">
					<table summary="오수 발생량 테이블 입니다" class="table_list">
						<caption>오수 발생량</caption>
						<colgroup> 
							<col span="4" width="25%" />
						</colgroup>
						<thead>
							<tr>
								<th scope="col">구분</th>
								<th scope="col">전일 지침</th>
								<th scope="col">금일 지침</th>
								<th scope="col">발생량</th>
							</tr>
						</thead>
						<tbody>
							<tr class="_calcAtype">
								<td>유입량</td>
								<td><input type="text" title="전일지침" id="pre_sdl_iflow_dwater" value="${resultVO.pre_sdl_iflow_dwater }" readonly="readonly"/></td>
								<td><input type="text" title="금일지침" id="sdl_iflow_dwater" name="sdl_iflow_dwater" value="${resultVO.sdl_iflow_dwater }" class="_subCalcA"/></td>
								<td><c:if test="${empty resultVO.sdl_iflow_dwater }">0</c:if><c:if test="${not empty resultVO.sdl_iflow_dwater }">${(resultVO.sdl_iflow_dwater)-(resultVO.pre_sdl_iflow_dwater)}</c:if></td>
							</tr>
							<tr class="_calcAtype">
								<td>방류량</td>
								<td><input type="text" title="전일지침" id="pre_sdl_oflow_dwater" value="${resultVO.pre_sdl_oflow_dwater }" readonly="readonly"/></td>
								<td><input type="text" title="금일지침" id="sdl_oflow_dwater" name="sdl_oflow_dwater" value="${resultVO.sdl_oflow_dwater }" class="_subCalcA"/></td>
								<td><c:if test="${empty resultVO.sdl_oflow_dwater }">0</c:if><c:if test="${not empty resultVO.sdl_oflow_dwater }">${(resultVO.sdl_oflow_dwater)-(resultVO.pre_sdl_oflow_dwater)}</c:if></td>
							</tr>
						</tbody>
					</table>
				</div><!--//table_wrap-->
				
				<h3 class="tit_h3">전력 사용량 (kw/일)</h3>
				<div class="table_wrap">
					<table summary="전력 사용량 테이블 입니다" class="table_list">
						<caption>전력 사용량</caption>
						<colgroup>
							<col span="4" width="25%" />
						</colgroup>
						<thead>
							<tr>
								<th scope="col">구분</th>
								<th scope="col">전일 지침</th>
								<th scope="col">금일 지침</th>
								<th scope="col">사용량</th>
							</tr>
						</thead>
						<tbody>
							<tr class="_calcAtype">
								<td>처리시설</td>
								<td><input type="text" title="전일지침" id="pre_sdl_elect_number" value="${resultVO.pre_sdl_elect_number }" readonly="readonly"/></td>
								<td><input type="text" title="금일지침" id="sdl_elect_number" name="sdl_elect_number" value="${resultVO.sdl_elect_number }" class="_subCalcA"/></td>
								<td><c:if test="${empty resultVO.sdl_elect_number }">0</c:if><c:if test="${not empty resultVO.sdl_elect_number }">${(resultVO.sdl_elect_number)-(resultVO.pre_sdl_elect_number)}</c:if></td>
							</tr>
						</tbody>
					</table>
				</div><!--//table_wrap-->
				
				<h3 class="tit_h3">약품사용 및 재고 현황</h3>
				<div class="table_wrap">
					<table summary="약품사용 및 재고 현황 테이블 입니다" class="table_list type_input" id="invenTable">
						<caption>약품사용 및 재고 현황</caption>
						<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
							<col width="15%" />
							<col width="17%" />
							<col width="17%" />
							<col width="17%" />
							<col width="17%" />
							<col width="17%" />
						</colgroup>
						<thead>
							<tr>
								<th scope="col">약품명</th>
								<th scope="col">전일 이월량(kg)</th>
								<th scope="col">금일 재고량(kg)</th>
								<th scope="col">금일 사용량(kg)</th>
								<th scope="col">입고량(kg)</th>
								<th scope="col">비고</th>
							</tr>
						</thead>
						<tbody>
						<c:if test="${empty resultVO.invenVOList}">
							<tr id="invenBaseTr" class="_calcBtype">
								<td style="display:none;"><input type="text" name="invenVOList[0].sui_code_key" class="_codeKey"/></td>
								<td><input type="text" name="invenVOList[0].sui_code_name" /></td>
								<td><input type="text" title="전일이월량" id="pre_sui_total_stock_0" value="0" readonly="readonly" class="preTs"/></td>
								<td><input type="text" title="금일재고량" id="sui_total_stock_0" name="invenVOList[0].sui_total_stock" readonly="readonly"/></td>
								<td><input type="text" title="금일사용량" id="sui_use_num_0" name="invenVOList[0].sui_use_num" class="_subCalcB" onkeyup="calcBtype();" onfocus="focusInput(this);" onblur="outfocusInput(this);"/></td>
								<td><input type="text" title="입고량" id="sui_in_num_0" name="invenVOList[0].sui_in_num" class="_subCalcB" onkeyup="calcBtype();" onfocus="focusInput(this);" onblur="outfocusInput(this);"/></td>
								<td><input type="text" title="비고" id="sui_use_note_0" name="invenVOList[0].sui_use_note" /></td>
							</tr>
						</c:if>
						<c:if test="${not empty resultVO.invenVOList}">
							<c:forEach var="result" items="${resultVO.invenVOList }" varStatus="status"> 
							<tr <c:if test="${status.first }">id="invenBaseTr"</c:if> class="_calcBtype">
								<td style="display:none;"><input type="text" name="invenVOList[${status.count-1}].sui_code_key" value="${result.sui_code_key }" class="_codeKey"/></td>
								<!--<td><input type="text" name="invenVOList[${status.count-1}].sui_code_name" value="${result.sui_code_name }" /></td> -->
								<td>${result.sui_code_name }</td>
								<td><input type="text" title="전일이월량" id="pre_sui_total_stock_${status.count-1}" value="${result.pre_sui_total_stock }" readonly="readonly"  class="preTs"/></td>
								<td><input type="text" title="금일재고량" id="sui_total_stock_${status.count-1}" name="invenVOList[${status.count-1}].sui_total_stock" value="${result.sui_total_stock }" readonly="readonly" /></td>
								<td><input type="text" title="금일사용량" id="sui_use_num_${status.count-1}" name="invenVOList[${status.count-1}].sui_use_num" value="${result.sui_use_num }" class="_subCalcB" onkeyup="calcBtype();" onfocus="focusInput(this);" onblur="outfocusInput(this);"/></td>
								<td><input type="text" title="입고량" id="sui_in_num_${status.count-1}" name="invenVOList[${status.count-1}].sui_in_num" value="${result.sui_in_num }" class="_subCalcB" onkeyup="calcBtype();" onfocus="focusInput(this);" onblur="outfocusInput(this);"/></td>
								<td><input type="text" title="비고" name="invenVOList[${status.count-1}].sui_use_note" value="${result.sui_use_note }" /></td>
							</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
				</div><!--//table_wrap-->
				
				<h3 class="tit_h3">기기류 점검 및 작업사항</h3>
				<div class="btn_bbs type_pm">
					<a href="#appendRow" onclick="appendRow('machineTable','machineBaseTr');return false;" class="btn_pm">+</a>
					<a href="#deleteRow" onclick="deleteRow('machineTable');return false;" class="btn_pm">-</a>
				</div>
				
				<div class="table_wrap"><!-- D : table은 div table_wrap 싸고감 -->
					<table summary="기기류 점검 및 작업사항 테이블 입니다" class="table_list" id="machineTable">
						<caption>기기류 점검 및 작업사항</caption>
						<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
							<col width="20%" />
							<col width="10%" />
							<col width="10%" />
							<col width="10%" />
							<col width="50%" />
						</colgroup>
						<thead>
							<tr>
								<th scope="col" rowspan="2" class="bdR">항목</th>
								<th scope="col" colspan="3" class="bdB">점검 결과</th>
								<th scope="col" rowspan="2" class="bdL">작업사항</th>
							</tr>
							<tr>
								<th scope="col">양호</th>
								<th scope="col" class="bdL">보통</th>
								<th scope="col"  class="bdL">불량</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${empty resultVO.dailyMachineVOList}">
								<tr id="machineBaseTr">
									<td><input type="text" title="항목" name="dailyMachineVOList[0].scm_check_name" /></td>
									<td><input type="radio" title="점검결과" name="dailyMachineVOList[0].scm_check_result" value="A" /></td>
									<td><input type="radio" title="점검결과" name="dailyMachineVOList[0].scm_check_result" value="B" /></td>
									<td><input type="radio" title="점검결과" name="dailyMachineVOList[0].scm_check_result" value="C" /></td>
									<td><input type="text" title="작업사항" size="50" name="dailyMachineVOList[0].scm_check_note" /></td>
								</tr>
							</c:if>
							<c:if test="${not empty resultVO.dailyMachineVOList}">
								<c:forEach var="result" items="${resultVO.dailyMachineVOList }" varStatus="status"> 
								<tr <c:if test="${status.first }">id="machineBaseTr"</c:if>>
									<td><input type="text" title="항목" name="dailyMachineVOList[${status.count-1}].scm_check_name" value="${result.scm_check_name }"/></td>
									<td><input type="radio" title="점검결과" name="dailyMachineVOList[${status.count-1}].scm_check_result" value="A" <c:if test="${result.scm_check_result eq 'A'}">checked="checked"</c:if> /></td>
									<td><input type="radio" title="점검결과" name="dailyMachineVOList[${status.count-1}].scm_check_result" value="B" <c:if test="${result.scm_check_result eq 'B'}">checked="checked"</c:if> /></td>
									<td><input type="radio" title="점검결과" name="dailyMachineVOList[${status.count-1}].scm_check_result" value="C" <c:if test="${result.scm_check_result eq 'C'}">checked="checked"</c:if> /></td>
									<td><input type="text" title="작업사항" size="50" name="dailyMachineVOList[${status.count-1}].scm_check_note" value="${result.scm_check_note }" /></td>
								</tr>
								</c:forEach>
							</c:if>
						</tbody>
					</table>
				</div><!--//table_wrap-->
				
				<h3 class="tit_h3">슬러지 처리량</h3>
				<div class="table_wrap"><!-- D : table은 div table_wrap 싸고감 -->
					<table summary="슬러지 처리량 테이블 입니다" class="table_list">
						<caption>슬러지 처리량</caption>
						<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
							<col span="3" width="33.3%" />
						</colgroup>
						<thead>
							<tr>
								<th scope="col">용량</th>
								<th scope="col">업체명</th>
								<th scope="col">금액</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td ><input type="text" title="용량" id="sdl_sludge_volm" name="sdl_sludge_volm" class="width_80" value="${resultVO.sdl_sludge_volm }"/></td>
								<td ><input type="text" title="업체명" id="sdl_sludge_comp" name="sdl_sludge_comp" class="width_80" value="${resultVO.sdl_sludge_comp }" /></td>
								<td ><input type="text" title="금액" id="sdl_sludge_cost" name="sdl_sludge_cost" class="width_80" value="${resultVO.sdl_sludge_cost }" /></td>
							</tr>
						</tbody>
					</table>
				</div><!--//table_wrap-->
				
				<h3 class="tit_h3">방류 수질 검사 (자가 측정 대행)</h3>
				<div class="table_wrap">
					<table summary="방류 수질 검사 (자가 측정 대행) 테이블 입니다" class="table_list">
						<caption>방류 수질 검사 (자가 측정 대행)</caption>
						<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
							<col width="16.5%" />
							<col width="16.5%" />
							<col width="16.5%" />
							<col width="16.5%" />
							<col width="16.5%" />
							<col width="17.5%" />
						</colgroup>
						<thead>
							<tr>
								<th scope="col">항목</th>
								<th scope="col">BOD</th>
								<th scope="col">SS</th>
								<th scope="col">T-N</th>
								<th scope="col">T-P</th>
								<th scope="col">총대장균군</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>수질기준</td>
								<td>10</td>
								<td>10</td>
								<td>20</td>
								<td>2</td>
								<td>3000m/ml</td>
							</tr>
							<tr>
								<td>결과치</td>
								<td><input type="text" title="BOD" id="sdl_bod_num" name="sdl_bod_num" value="${resultVO.sdl_bod_num }" class="width_50"/></td>
								<td><input type="text" title="SS" id="sdl_ss_num" name="sdl_ss_num" value="${resultVO.sdl_ss_num }" class="width_50"/></td>
								<td><input type="text" title="T-N" id="sdl_tn_num" name="sdl_tn_num" value="${resultVO.sdl_tn_num }" class="width_50"/></td>
								<td><input type="text" title="T-P" id="sdl_tp_num" name="sdl_tp_num" value="${resultVO.sdl_tp_num }" class="width_50"/></td>
								<td><input type="text" title="총대장균군" id="sdl_ec_num" name="sdl_ec_num" value="${resultVO.sdl_ec_num }" class="width_50"/></td>
							</tr>
																		  
						</tbody>
					</table>
				</div><!--//table_wrap-->
				<h3 class="tit_h3">시험성적서</h3>
				<div class="table_wrap">
					<table summary="특이사항 목록 입니다" class="table_write">
					<caption>특이사항 목록</caption>
					<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
						<col width="15%" />
						<col width="85%" />
					</colgroup>
					<tbody>
						<tr>
							<th scope="row">첨부파일</th>
							<td class="alL"><input type="file"  name="file" id="file" title="첨부파일 선택" class="width_40" onchange="uploadFile(fileOtions);" />
							<span id="fileInfo">
								<c:if test="${not empty resultVO.sdl_dlog_file }">
									<c:set var="saveFile" value="${fn:split(resultVO.sdl_dlog_file,'**')}" />
									<a href="<c:url value='/fileDownload.do'/>?fileInfo=${resultVO.sdl_dlog_file}" onclick="fileDown();return false;" class="file_down ${str:getFileType(saveFile[0])}" >${saveFile[1] }(${saveFile[2]})</a>
									<a href="#fileDelete" id="fileDelete" class="btn_gy" onclick="fileDelete();return false;">파일 삭제</a>
								</c:if>
							</span></td>
						</tr>
					</tbody>
					</table>
				</div>
				<h3 class="tit_h3">특이사항</h3>
				<!-- 수정
				<div class="radio_sec">
					<ul class="radio_area">
						<li><label for="sdl_unusual_yn">보통</label><input id="sdl_unusual_yn" name="sdl_unusual_yn" type="radio" value="Y" <c:if test="${resultVO.sdl_unusual_yn eq 'Y' or empty resultVO.sdl_unusual_yn}">checked="checked"</c:if>/></li>
						<li><label for="sdl_unusual_yn">심각</label><input id="sdl_unusual_yn" name="sdl_unusual_yn" type="radio" value="N" <c:if test="${resultVO.sdl_unusual_yn eq 'N' }">checked="checked"</c:if>/></li>
					</ul>
					<textarea name="sdl_unusual_cont">${resultVO.sdl_unusual_cont }</textarea>
				</div>
				-->
				<div class="table_wrap">
					<table summary="특이사항 목록 입니다" class="table_write">
						<caption>특이사항 목록</caption>
						<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
							<col width="15%" />
							<col width="85%" />
						</colgroup>
						<tbody>
							<tr>
								<th scope="row">상태</th>
								<td class="alL">
									<ul class="radio_area">
										<li><label for="sdl_unusual_yn">보통</label><input id="sdl_unusual_yn" name="sdl_unusual_yn" type="radio" value="Y" <c:if test="${resultVO.sdl_unusual_yn eq 'Y' or empty resultVO.sdl_unusual_yn}">checked="checked"</c:if>/></li>
										<li><label for="sdl_unusual_yn">심각</label><input id="sdl_unusual_yn" name="sdl_unusual_yn" type="radio" value="N" <c:if test="${resultVO.sdl_unusual_yn eq 'N' }">checked="checked"</c:if>/></li>
									</ul>
								</td>
							</tr>
							<tr>
								<th scope="row">내용</th>
								<td class="alL"><textarea name="sdl_unusual_cont">${resultVO.sdl_unusual_cont }</textarea></td>
							</tr>							
						</tbody>
					</table>
				</div>
				
				<div class="btn_bbs">
					<a href="<c:url value='/daily/dailyList.do' />" class="btn_wh" onclick="listPage();return false;">목록</a>
					<a href="<c:url value="/daily/dailySave.do"/>" class="btn_re" onclick="saveFormPage();return false;">저장</a>
				</div>
			</form>
		</div><!--//container_area-->
	</div>
<jsp:include page="../include/fileUpload.jsp" flush="true"/>
<jsp:include page="../include/fileDownload.jsp" flush="false">
	<jsp:param name="fileInfo" value="${resultVO.sdl_dlog_file}" />
</jsp:include>
<jsp:include page="../include/footer.jsp" flush="true"/>